﻿using System;
using Codeplus.Dhruvtaata.Web.Tools;

namespace Codeplus.Dhruvtaata.Web.Models.Entity {
    public abstract class Person {
        public int PersonId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime DateOfBirth { get; set; }
        public string EmailAddress { get; set; }
        public string ContactPhone { get; set; }
        public virtual Address ContactAddress { get; set; }

        public override string ToString() {
            return string.Format("{0}-{1}-{2}-{3}",
                string.IsNullOrEmpty(this.FirstName) ? string.Empty : this.FirstName.ToLower(),
                string.IsNullOrEmpty(this.LastName) ? string.Empty : this.LastName.ToLower(),
                string.IsNullOrEmpty(this.EmailAddress) ? string.Empty : this.EmailAddress.ToLower(),
                string.IsNullOrEmpty(this.ContactPhone) ? string.Empty : this.ContactPhone.ToLower());
        }

        public override bool Equals(object obj) {
            var target = obj as Person;
            var hash1 = Encryption.CalculateMD5Hash(this.ToString());
            var hash2 = Encryption.CalculateMD5Hash(target.ToString());
            return hash1 == hash2;
        }

        public override int GetHashCode() {
            return base.GetHashCode();
        }
    }
}